<!--
 * @Description: 
 * @Author: qingyang
 * @Date: 2023-06-08 15:26:47
 * @LastEditors: qingyang
 * @LastEditTime: 2023-06-12 19:03:41
-->
<template>
  <div class="flow-content-body">
    <slot name="default" :hidden-line="true"></slot>
    <audit-form
      ref="auditFormRef"
      :data="factorDetail"
      v-if="
        pageType == TodoTaskStatusEnum.PENDING &&
        processInfo?.taskDefinitionKey === TaskDefinitionKeyFactorEnum.PCF_FACTOR_SUBMIT_INFO
      "
    ></audit-form>
    <GFlowDesc v-else>
      <GFlowDescItem label="因子名称：" :value="factorDetail?.factorName" />
      <GFlowDescItem label="英文名称：" :value="factorDetail?.enName" />
      <GFlowDescItem label="类别：" :value="$t18(`factor.${factorDetail?.category}`)" />
      <GFlowDescItem label="排放因子：" :value="factorDetail?.emissionFactor" />
      <GFlowDescItem label="单位：" :value="factorDetail?.factorUnit" />
      <GFlowDescItem label="国别：" :value="factorDetail?.country" />
      <GFlowDescItem label="基准年：" :value="factorDetail?.baseYear" />
      <GFlowDescItem label="来源类型：" :value="$t18(`factor.${factorDetail?.factorCreateType}`)" />
      <GFlowDescItem label="数据来源：" :value="$t18(`factor.${factorDetail?.factorDataSource}`)" />
      <GFlowDescItem label="核算边界：" :value="$t18(`factor.${factorDetail?.boundary}`)" />
      <GFlowDescItem label="版本：" :value="factorDetail?.version" />
      <GFlowDescItem label="附件：">
        <GFileLink
          :url="factorDetail?.attachment"
          :filename="factorDetail?.attachmentName"
          v-if="factorDetail?.attachmentName && factorDetail?.attachment"
        />
        <span v-else>-</span>
      </GFlowDescItem>
      <GFlowDescItem :span="16" label="备注：" :value="factorDetail?.comment" />
    </GFlowDesc>
  </div>
</template>
<script lang="ts">
export default {
  name: 'FactorAudit'
};
</script>
<script lang="ts" setup>
import { ref, defineExpose, defineProps, inject } from 'vue';
import { GFlowDesc, GFlowDescItem } from '@/components/GFlowDesc';
import GFileLink from '@/components/GFileLink/index.vue';
import AuditForm from './components/AuditForm/index.vue';
import { getFactorDetail } from '@/apis/todo/flowBusiness';
import type { IFactorDetail } from '@/apis/todo/model/flowBusinessModel';
import { TODO_DETAIL_ROOT } from '../../types';
import type { TodoDetailRootProvider } from '../../types';
import { TodoTaskStatusEnum, TaskDefinitionKeyFactorEnum } from '@/constants/enum';

interface FactorAuditProps {
  businessKey: string;
}
const props = defineProps<FactorAuditProps>();
const { pageType, processInfo } = inject(TODO_DETAIL_ROOT) as TodoDetailRootProvider;

const auditFormRef = ref();
const factorDetail = ref({} as IFactorDetail);
async function getData() {
  try {
    factorDetail.value = await getFactorDetail(props.businessKey);
  } catch (error) {
    console.log('error', error);
  }
}

getData();

function submit() {
  return auditFormRef.value?.submit();
}

defineExpose({
  submit
});
</script>
<style lang="scss" scoped>
.flow-content-body {
  padding: 12px 24px 62px;
}
</style>
